package com.ysd.lis.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.SysUserInstrSetup;
import com.ysd.lis.mapper.sys.SysUserInstrSetupMapper;
import com.ysd.lis.service.SysUserInstrSetupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户仪器关系表 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-01-04
 */
@Service
public class SysUserInstrSetupServiceImpl extends ServiceImpl<SysUserInstrSetupMapper, SysUserInstrSetup> implements SysUserInstrSetupService {

    @Autowired
    private SysUserInstrSetupMapper sysUserInstrSetupMapper;
    @Override
    public Result findSysUserInstrSetupList(String userId) {
        LambdaQueryWrapper<SysUserInstrSetup> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysUserInstrSetup::getUserId, userId);
        lambdaQueryWrapper.eq(SysUserInstrSetup::getDelFlag, 0);
        List<SysUserInstrSetup> sysUserInstrSetups = sysUserInstrSetupMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功", sysUserInstrSetups);
    }
    @Override
    public Result addUserInstrSetUp(SysUserInstrSetup sysUserInstrSetup) {
        boolean save = this.save(sysUserInstrSetup);
        if (save) {
            return Result.succ(1, "添加成功", save);
        } else {
            return Result.fail("添加成功");
        }
    }

    @Override
    public Result addBatchUserInstrSetUp(List<SysUserInstrSetup> sysUserInstrSetups) {
        boolean save = this.saveBatch(sysUserInstrSetups);
        if (save) {
            return Result.succ(1, "添加成功", save);
        } else {
            return Result.fail("添加成功");
        }
    }

    @Override
    public Result deleteUserInstrSetUp(SysUserInstrSetup sysUserInstrSetup) {
        LambdaQueryWrapper<SysUserInstrSetup> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StrUtil.isNotEmpty(sysUserInstrSetup.getUserId()), SysUserInstrSetup::getUserId, sysUserInstrSetup.getUserId());
        lambdaQueryWrapper.eq(StrUtil.isNotEmpty(sysUserInstrSetup.getInstrSetupId()),SysUserInstrSetup::getInstrSetupId, sysUserInstrSetup.getInstrSetupId());
        int delete = sysUserInstrSetupMapper.delete(lambdaQueryWrapper);
        if (delete >= 0) {
            return Result.succ(1, "添加成功", delete);
        } else {
            return Result.fail("添加成功");
        }
    }

}
